package com.muyu.system.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.system.domain.DanmoShoppingFootprint;
import com.muyu.system.service.IDanmoShoppingFootprintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品足迹Controller
 *
 * @author yangle
 * @date 2024-09-29
 */
@RestController
@RequestMapping("/footprint")
public class DanmoShoppingFootprintController extends BaseController
{
    @Autowired
    private IDanmoShoppingFootprintService danmoShoppingFootprintService;

    /**
     * 查询商品足迹列表
     */
//    @RequiresPermissions("system:footprint:list")
    @PostMapping("/list")
    public Result list(@RequestBody DanmoShoppingFootprint danmoShoppingFootprint)
    {
        PageHelper.startPage(danmoShoppingFootprint.getPageNum(),danmoShoppingFootprint.getPageSize());
        List<DanmoShoppingFootprint> list = danmoShoppingFootprintService.selectDanmoShoppingFootprintList(danmoShoppingFootprint);
        PageInfo<DanmoShoppingFootprint> danmoShoppingFootprintPageInfo = new PageInfo<>(list);
        return Result.success(danmoShoppingFootprintPageInfo);
    }

    /**
     * 导出商品足迹列表
     */
//    @RequiresPermissions("system:footprint:export")
    @Log(title = "商品足迹", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoShoppingFootprint danmoShoppingFootprint)
    {
        List<DanmoShoppingFootprint> list = danmoShoppingFootprintService.selectDanmoShoppingFootprintList(danmoShoppingFootprint);
        ExcelUtil<DanmoShoppingFootprint> util = new ExcelUtil<DanmoShoppingFootprint>(DanmoShoppingFootprint.class);
        util.exportExcel(response, list, "商品足迹数据");
    }

    /**
     * 获取商品足迹详细信息
     */
//    @RequiresPermissions("system:footprint:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoShoppingFootprintService.selectDanmoShoppingFootprintById(id));
    }

    /**
     * 新增商品足迹
     */
//    @RequiresPermissions("system:footprint:add")
    @Log(title = "商品足迹", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoShoppingFootprint danmoShoppingFootprint)
    {
        return toAjax(danmoShoppingFootprintService.insertDanmoShoppingFootprint(danmoShoppingFootprint));
    }

    /**
     * 修改商品足迹
     */
//    @RequiresPermissions("system:footprint:edit")
    @Log(title = "商品足迹", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoShoppingFootprint danmoShoppingFootprint)
    {
        return toAjax(danmoShoppingFootprintService.updateDanmoShoppingFootprint(danmoShoppingFootprint));
    }

    /**
     * 删除商品足迹
     */
    @RequiresPermissions("system:footprint:remove")
    @Log(title = "商品足迹", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoShoppingFootprintService.deleteDanmoShoppingFootprintByIds(ids));
    }
}
